# Copyright 2023 Remy Blank <remy@c-space.org>
# SPDX-License-Identifier: MIT

mlua_add_lua_test_modules(mlua_mod_00_setup_test 00_setup.test.lua)
target_link_libraries(mlua_mod_00_setup_test INTERFACE
    mlua_mod_hardware_uart
    mlua_mod_pico_stdlib
)

mlua_add_c_module(mlua_mod_hardware_adc hardware.adc.c)
target_link_libraries(mlua_mod_hardware_adc INTERFACE
    hardware_adc
    hardware_irq
    mlua_mod_mlua_event_headers
    pico_platform
)

mlua_add_lua_test_modules(mlua_mod_hardware_adc_test hardware.adc.test.lua)
target_link_libraries(mlua_mod_hardware_adc_test INTERFACE
    mlua_mod_hardware_adc
    mlua_mod_pico_time
)

mlua_add_c_module(mlua_mod_hardware_base hardware.base.c)
target_link_libraries(mlua_mod_hardware_base INTERFACE
    hardware_base
)

mlua_add_lua_test_modules(mlua_mod_hardware_base_test
    hardware.base.test.lua)
target_link_libraries(mlua_mod_hardware_base_test INTERFACE
    mlua_mod_hardware_base
    mlua_mod_hardware_regs_addressmap
    mlua_mod_hardware_regs_watchdog
    mlua_mod_mlua_list
)

mlua_add_c_module(mlua_mod_hardware_clocks hardware.clocks.c)
target_link_libraries(mlua_mod_hardware_clocks INTERFACE
    hardware_clocks
)

mlua_add_lua_test_modules(mlua_mod_hardware_clocks_test
    hardware.clocks.test.lua)
target_link_libraries(mlua_mod_hardware_clocks_test INTERFACE
    mlua_mod_hardware_clocks
    mlua_mod_hardware_regs_clocks
    mlua_mod_table
)

mlua_add_c_module(mlua_mod_hardware_flash hardware.flash.c)
target_link_libraries(mlua_mod_hardware_flash INTERFACE
    hardware_flash
)

mlua_add_lua_test_modules(mlua_mod_hardware_flash_test
    hardware.flash.test.lua)
target_link_libraries(mlua_mod_hardware_flash_test INTERFACE
    mlua_mod_hardware_flash
    mlua_mod_hardware_regs_addressmap
    mlua_mod_hardware_sync
    mlua_mod_mlua_mem
    mlua_mod_pico
    mlua_mod_pico_unique_id
    mlua_mod_string
)

mlua_add_c_module(mlua_mod_hardware_gpio hardware.gpio.c)
target_link_libraries(mlua_mod_hardware_gpio INTERFACE
    hardware_gpio
    hardware_structs
    hardware_sync
    mlua_mod_mlua_event_headers
    pico_platform
)

mlua_add_lua_test_modules(mlua_mod_hardware_gpio_test hardware.gpio.test.lua)
target_link_libraries(mlua_mod_hardware_gpio_test INTERFACE
    mlua_mod_hardware_gpio
    mlua_mod_hardware_irq
    mlua_mod_mlua_list
    mlua_mod_mlua_thread
    mlua_mod_mlua_util
    mlua_mod_pico
    mlua_mod_string
)

mlua_add_c_module(mlua_mod_hardware_i2c hardware.i2c.c)
target_include_directories(mlua_mod_hardware_i2c_headers INTERFACE
    include_hardware.i2c)
target_link_libraries(mlua_mod_hardware_i2c INTERFACE
    hardware_i2c
    mlua_mod_mlua_event_headers
    mlua_mod_mlua_int64
    pico_base
    pico_time
)

mlua_add_lua_test_modules(mlua_mod_hardware_i2c_test hardware.i2c.test.lua)
target_link_libraries(mlua_mod_hardware_i2c_test INTERFACE
    mlua_mod_hardware_base
    mlua_mod_hardware_i2c
    mlua_mod_hardware_regs_addressmap
    mlua_mod_hardware_regs_i2c
    mlua_mod_mlua_testing_i2c
    mlua_mod_mlua_thread
    mlua_mod_pico_multicore
)

mlua_add_c_module(mlua_mod_hardware_irq hardware.irq.c)
target_link_libraries(mlua_mod_hardware_irq INTERFACE
    hardware_irq
    hardware_structs
    hardware_sync
    mlua_mod_mlua_event_headers
    pico_platform
)

mlua_add_lua_test_modules(mlua_mod_hardware_irq_test hardware.irq.test.lua)
target_link_libraries(mlua_mod_hardware_irq_test INTERFACE
    mlua_mod_hardware_irq
    mlua_mod_mlua_list
    mlua_mod_mlua_thread
    mlua_mod_string
)

mlua_add_c_module(mlua_mod_hardware_pll hardware.pll.c)
target_link_libraries(mlua_mod_hardware_pll INTERFACE
    hardware_pll
)

mlua_add_lua_test_modules(mlua_mod_hardware_pll_test hardware.pll.test.lua)
target_link_libraries(mlua_mod_hardware_pll_test INTERFACE
    mlua_mod_hardware_clocks
    mlua_mod_hardware_regs_clocks
    mlua_mod_hardware_pll
    mlua_mod_mlua_testing_clocks
    mlua_mod_pico_stdlib
)

mlua_add_lua_test_modules(mlua_mod_hardware_regs_test hardware.regs.test.lua)

file(GLOB paths LIST_DIRECTORIES false CONFIGURE_DEPENDS
    "${PICO_SDK_PATH}/src/rp2040/hardware_regs/include/hardware/regs/*.h")
foreach(path IN LISTS paths)
    cmake_path(GET path STEM LAST_ONLY name)
    string(TOUPPER "${name}" uname)
    set(target "mlua_mod_hardware_regs_${name}")
    mlua_add_header_module("${target}" "hardware.regs.${name}" "${path}"
        EXCLUDE "_ACCESS:\"...?\"$" "_RESET:\"%-\"$" "^isr_"
        STRIP "^(${uname}_)"
    )
    target_link_libraries("${target}" INTERFACE hardware_regs)
    target_link_libraries(mlua_mod_hardware_regs_test INTERFACE "${target}")
endforeach()

target_link_libraries(mlua_mod_hardware_regs_test INTERFACE
    mlua_mod_hardware_regs_addressmap
    mlua_mod_hardware_regs_intctrl
    mlua_mod_hardware_regs_vreg_and_chip_reset
)

mlua_add_c_module(mlua_mod_hardware_resets hardware.resets.c)
target_link_libraries(mlua_mod_hardware_resets INTERFACE
    hardware_resets
)

mlua_add_lua_test_modules(mlua_mod_hardware_resets_test
    hardware.resets.test.lua)
target_link_libraries(mlua_mod_hardware_resets_test INTERFACE
    mlua_mod_hardware_base
    mlua_mod_hardware_regs_adc
    mlua_mod_hardware_regs_addressmap
    mlua_mod_hardware_regs_resets
    mlua_mod_hardware_resets
)

mlua_add_c_module(mlua_mod_hardware_rtc hardware.rtc.c)
target_link_libraries(mlua_mod_hardware_rtc INTERFACE
    hardware_rtc
    mlua_mod_mlua_event_headers
)

mlua_add_lua_test_modules(mlua_mod_hardware_rtc_test hardware.rtc.test.lua)
target_link_libraries(mlua_mod_hardware_rtc_test INTERFACE
    mlua_mod_hardware_clocks
    mlua_mod_hardware_regs_resets
    mlua_mod_hardware_resets
    mlua_mod_hardware_rtc
    mlua_mod_mlua_thread
    mlua_mod_mlua_util
)

mlua_add_c_module(mlua_mod_hardware_spi hardware.spi.c)
target_link_libraries(mlua_mod_hardware_spi INTERFACE
    hardware_base
    hardware_irq
    hardware_regs
    hardware_spi
    mlua_mod_mlua_event_headers
    pico_platform
)

mlua_add_lua_test_modules(mlua_mod_hardware_spi_test hardware.spi.test.lua)
target_link_libraries(mlua_mod_hardware_spi_test INTERFACE
    mlua_mod_hardware_regs_addressmap
    mlua_mod_hardware_spi
    mlua_mod_string
)

mlua_add_c_module(mlua_mod_hardware_sync hardware.sync.c)
target_link_libraries(mlua_mod_hardware_sync INTERFACE
    hardware_sync
)

mlua_add_lua_test_modules(mlua_mod_hardware_sync_test hardware.sync.test.lua)
target_link_libraries(mlua_mod_hardware_sync_test INTERFACE
    mlua_mod_hardware_irq
    mlua_mod_hardware_sync
    mlua_mod_mlua_thread
)

mlua_add_c_module(mlua_mod_hardware_timer hardware.timer.c)
target_link_libraries(mlua_mod_hardware_timer INTERFACE
    hardware_timer
    mlua_mod_mlua_event_headers
    mlua_mod_mlua_int64
    mlua_mod_mlua_thread
    pico_platform
)

mlua_add_lua_test_modules(mlua_mod_hardware_timer_test hardware.timer.test.lua)
target_link_libraries(mlua_mod_hardware_timer_test INTERFACE
    mlua_mod_hardware_timer
    mlua_mod_mlua_int64
    mlua_mod_table
)

mlua_add_c_module(mlua_mod_hardware_uart hardware.uart.c)
target_include_directories(mlua_mod_hardware_uart_headers INTERFACE
    include_hardware.uart)
target_link_libraries(mlua_mod_hardware_uart INTERFACE
    hardware_base
    hardware_irq
    hardware_regs
    hardware_uart
    mlua_mod_mlua_event_headers
    mlua_mod_mlua_int64
    pico_platform
    pico_time
)

mlua_add_lua_test_modules(mlua_mod_hardware_uart_test hardware.uart.test.lua)
target_link_libraries(mlua_mod_hardware_uart_test INTERFACE
    mlua_mod_hardware_regs_addressmap
    mlua_mod_hardware_uart
    mlua_mod_math
    mlua_mod_mlua_list
    mlua_mod_mlua_testing_uart
    mlua_mod_mlua_thread
    mlua_mod_pico_time
    mlua_mod_string
)

mlua_add_c_module(mlua_mod_hardware_vreg hardware.vreg.c)
target_link_libraries(mlua_mod_hardware_vreg INTERFACE
    hardware_vreg
)

mlua_add_lua_test_modules(mlua_mod_hardware_vreg_test hardware.vreg.test.lua)
target_link_libraries(mlua_mod_hardware_vreg_test INTERFACE
    mlua_mod_hardware_base
    mlua_mod_hardware_vreg
    mlua_mod_hardware_regs_addressmap
    mlua_mod_hardware_regs_vreg_and_chip_reset
)

mlua_add_c_module(mlua_mod_hardware_watchdog hardware.watchdog.c)
target_link_libraries(mlua_mod_hardware_watchdog INTERFACE
    hardware_watchdog
)

mlua_add_lua_test_modules(mlua_mod_hardware_watchdog_test
    hardware.watchdog.test.lua)
target_link_libraries(mlua_mod_hardware_watchdog_test INTERFACE
    mlua_mod_hardware_base
    mlua_mod_hardware_regs_addressmap
    mlua_mod_hardware_regs_psm
    mlua_mod_hardware_regs_watchdog
    mlua_mod_hardware_watchdog
    mlua_mod_pico_time
)

mlua_add_c_module(mlua_mod_hardware_xosc hardware.xosc.c)
target_link_libraries(mlua_mod_hardware_xosc INTERFACE
    hardware_xosc
)

mlua_add_lua_test_modules(mlua_mod_hardware_xosc_test hardware.xosc.test.lua)
target_link_libraries(mlua_mod_hardware_xosc_test INTERFACE
    mlua_mod_hardware_xosc
)

mlua_add_lua_modules(mlua_mod_mlua mlua.lua)
target_link_libraries(mlua_mod_mlua INTERFACE
    mlua_mod_package
)

mlua_add_lua_test_modules(mlua_mod_mlua_test mlua.test.lua)
target_link_libraries(mlua_mod_mlua_test INTERFACE
    mlua_mod_mlua_io
    mlua_mod_pico
    mlua_mod_table
)

mlua_add_lua_test_modules(mlua_mod_mlua_config_test mlua.config.test.lua)

mlua_add_c_module(mlua_mod_mlua_event mlua.event.c)
target_include_directories(mlua_mod_mlua_event_headers INTERFACE
    include_mlua.event)
target_link_libraries(mlua_mod_mlua_event INTERFACE
    hardware_irq
    hardware_sync
    mlua_mod_mlua_int64
    pico_platform
    pico_time
)

mlua_add_c_module(mlua_mod_mlua_int64 mlua.int64.c)
target_include_directories(mlua_mod_mlua_int64_headers INTERFACE
    include_mlua.int64)

mlua_add_lua_test_modules(mlua_mod_mlua_int64_test mlua.int64.test.lua)
target_link_libraries(mlua_mod_mlua_int64_test INTERFACE
    mlua_mod_math
    mlua_mod_mlua_int64
    mlua_mod_mlua_util
    mlua_mod_string
    mlua_mod_table
)

mlua_add_lua_modules(mlua_mod_mlua_io mlua.io.lua)
target_link_libraries(mlua_mod_mlua_io INTERFACE
    mlua_mod_mlua_oo
    mlua_mod_string
    mlua_mod_table
)

mlua_add_lua_test_modules(mlua_mod_mlua_io_test mlua.io.test.lua)
target_link_libraries(mlua_mod_mlua_io_test INTERFACE
    mlua_mod_mlua_io
    mlua_mod_mlua_oo
)

mlua_add_c_module(mlua_mod_mlua_list mlua.list.c)

mlua_add_lua_test_modules(mlua_mod_mlua_list_test mlua.list.test.lua)
target_link_libraries(mlua_mod_mlua_list_test INTERFACE
    mlua_mod_mlua_list
    mlua_mod_mlua_util
    mlua_mod_table
)

mlua_add_c_module(mlua_mod_mlua_mem mlua.mem.c)

mlua_add_lua_test_modules(mlua_mod_mlua_mem_test
    mlua.mem.test.lua)
target_link_libraries(mlua_mod_mlua_mem_test INTERFACE
    mlua_mod_mlua_mem
    mlua_mod_string
)

mlua_add_lua_modules(mlua_mod_mlua_oo mlua.oo.lua)

mlua_add_lua_test_modules(mlua_mod_mlua_oo_test mlua.oo.test.lua)
target_link_libraries(mlua_mod_mlua_oo_test INTERFACE
    mlua_mod_mlua_oo
    mlua_mod_string
)

mlua_add_c_module(mlua_mod_mlua_stdio mlua.stdio.c)
target_link_libraries(mlua_mod_mlua_stdio INTERFACE
    mlua_mod_pico_stdio_headers
    pico_stdio
)

mlua_add_lua_test_modules(mlua_mod_mlua_stdio_test mlua.stdio.test.lua)
target_link_libraries(mlua_mod_mlua_stdio_test INTERFACE
    mlua_mod_mlua_io
    mlua_mod_mlua_list
    mlua_mod_mlua_stdio
    mlua_mod_mlua_testing_stdio
    mlua_mod_mlua_util
)

mlua_add_lua_modules(mlua_mod_mlua_testing mlua.testing.lua)
target_link_libraries(mlua_mod_mlua_testing INTERFACE
    mlua_mod_debug
    mlua_mod_math
    mlua_mod_mlua_io
    mlua_mod_mlua_list
    mlua_mod_mlua_oo
    mlua_mod_mlua_util
    mlua_mod_package
    mlua_mod_pico_time
    mlua_mod_string
    mlua_mod_table
)

mlua_add_lua_test_modules(mlua_mod_mlua_testing_test mlua.testing.test.lua)
target_link_libraries(mlua_mod_mlua_testing_test INTERFACE
    mlua_mod_mlua_list
    mlua_mod_mlua_util
    mlua_mod_table
)

mlua_add_lua_modules(mlua_mod_mlua_testing_clocks mlua.testing.clocks.lua)
target_link_libraries(mlua_mod_mlua_testing_clocks INTERFACE
    mlua_mod_hardware_clocks
    mlua_mod_hardware_uart
    mlua_mod_pico_stdio
    mlua_mod_pico_stdlib
)

mlua_add_lua_modules(mlua_mod_mlua_testing_i2c mlua.testing.i2c.lua)
target_link_libraries(mlua_mod_mlua_testing_i2c INTERFACE
    mlua_mod_hardware_gpio
    mlua_mod_hardware_i2c
    mlua_mod_mlua_list
)

mlua_add_lua_modules(mlua_mod_mlua_testing_stdio mlua.testing.stdio.lua)
target_link_libraries(mlua_mod_mlua_testing_stdio INTERFACE
    mlua_mod_hardware_gpio
    mlua_mod_hardware_uart
    mlua_mod_mlua_testing_uart
    mlua_mod_pico_stdio
    mlua_mod_pico_stdio_uart
)

mlua_add_lua_modules(mlua_mod_mlua_testing_uart mlua.testing.uart.lua)
target_link_libraries(mlua_mod_mlua_testing_uart INTERFACE
    mlua_mod_hardware_gpio
    mlua_mod_hardware_uart
)

mlua_add_lua_modules(mlua_mod_mlua_thread mlua.thread.lua)
target_link_libraries(mlua_mod_mlua_thread INTERFACE
    mlua_mod_coroutine
    mlua_mod_mlua_event
    mlua_mod_mlua_oo
    mlua_mod_pico_time
    mlua_mod_string
    mlua_mod_table
)

mlua_add_lua_test_modules(mlua_mod_mlua_thread_test mlua.thread.test.lua)
target_link_libraries(mlua_mod_mlua_thread_test INTERFACE
    mlua_mod_mlua_thread
    mlua_mod_string
)

mlua_add_lua_modules(mlua_mod_mlua_util mlua.util.lua)
target_link_libraries(mlua_mod_mlua_util INTERFACE
    mlua_mod_math
    mlua_mod_mlua_list
    mlua_mod_string
    mlua_mod_table
)

mlua_add_lua_test_modules(mlua_mod_mlua_util_test mlua.util.test.lua)
target_link_libraries(mlua_mod_mlua_util_test INTERFACE
    mlua_mod_mlua_util
    mlua_mod_table
)

mlua_add_c_module(mlua_mod_pico pico.c)
target_link_libraries(mlua_mod_pico INTERFACE
    pico_base
)

mlua_add_lua_test_modules(mlua_mod_pico_test pico.test.lua)
target_link_libraries(mlua_mod_pico_test INTERFACE
    mlua_mod_pico
)

mlua_add_header_module(mlua_mod_pico_board pico.board
    "${CMAKE_BINARY_DIR}/generated/pico_base/pico/config_autogen.h")
target_link_libraries(mlua_mod_pico INTERFACE
    pico_base
)

mlua_add_lua_test_modules(mlua_mod_pico_board_test pico.board.test.lua)
target_link_libraries(mlua_mod_pico_board_test INTERFACE
    mlua_mod_pico_board
)

mlua_add_c_module(mlua_mod_pico_i2c_slave pico.i2c_slave.c)
target_link_libraries(mlua_mod_pico_i2c_slave INTERFACE
    hardware_i2c
    mlua_mod_hardware_i2c
    mlua_mod_mlua_event
)

mlua_add_lua_test_modules(mlua_mod_pico_i2c_slave_test pico.i2c_slave.test.lua)
target_link_libraries(mlua_mod_pico_i2c_slave_test INTERFACE
    mlua_mod_mlua_testing_i2c
    mlua_mod_pico_i2c_slave
)

mlua_add_c_module(mlua_mod_pico_multicore pico.multicore.c)
target_link_libraries(mlua_mod_pico_multicore INTERFACE
    mlua_mod_mlua_event
    pico_multicore
    pico_platform
)

mlua_add_lua_test_modules(mlua_mod_pico_multicore_test pico.multicore.test.lua)
target_link_libraries(mlua_mod_pico_multicore_test INTERFACE
    mlua_mod_pico_multicore
)

mlua_add_c_module(mlua_mod_pico_multicore_fifo pico.multicore.fifo.c)
target_link_libraries(mlua_mod_pico_multicore_fifo INTERFACE
    hardware_structs
    mlua_mod_mlua_event_headers
    mlua_mod_mlua_int64
    pico_multicore
    pico_platform
    pico_time
)

mlua_add_lua_test_modules(mlua_mod_pico_multicore_fifo_test
    pico.multicore.fifo.test.lua)
target_link_libraries(mlua_mod_pico_multicore_fifo_test INTERFACE
    mlua_mod_mlua_thread
    mlua_mod_pico_multicore
    mlua_mod_pico_multicore_fifo
)

mlua_add_c_module(mlua_mod_pico_platform pico.platform.c)
target_link_libraries(mlua_mod_pico_platform INTERFACE
    pico_platform
)

mlua_add_lua_test_modules(mlua_mod_pico_platform_test pico.platform.test.lua)
target_link_libraries(mlua_mod_pico_platform_test INTERFACE
    mlua_mod_hardware_clocks
    mlua_mod_math
    mlua_mod_pico_platform
    mlua_mod_pico_time
)

mlua_add_c_module(mlua_mod_pico_stdio pico.stdio.c)
target_include_directories(mlua_mod_pico_stdio_headers INTERFACE
    include_pico.stdio)
target_link_libraries(mlua_mod_pico_stdio INTERFACE
    mlua_mod_mlua_event_headers
    mlua_mod_mlua_int64
    pico_stdio
    pico_time
)

mlua_add_lua_test_modules(mlua_mod_pico_stdio_test pico.stdio.test.lua)
target_link_libraries(mlua_mod_pico_stdio_test INTERFACE
    mlua_mod_mlua_list
    mlua_mod_mlua_testing_stdio
    mlua_mod_mlua_thread
    mlua_mod_mlua_util
    mlua_mod_pico_stdio
    mlua_mod_string
)

mlua_add_c_module(mlua_mod_pico_stdio_semihosting pico.stdio.semihosting.c)
target_link_libraries(mlua_mod_pico_stdio_semihosting INTERFACE
    hardware_exception
    pico_stdio_semihosting
)

mlua_add_lua_test_modules(mlua_mod_pico_stdio_semihosting_test
    pico.stdio.semihosting.test.lua)
target_link_libraries(mlua_mod_pico_stdio_semihosting_test INTERFACE
    mlua_mod_pico_stdio
    mlua_mod_pico_stdio_semihosting
)

mlua_add_c_module(mlua_mod_pico_stdio_uart pico.stdio.uart.c)
target_link_libraries(mlua_mod_pico_stdio_uart INTERFACE
    mlua_mod_hardware_uart_headers
    pico_stdio_uart
)

mlua_add_lua_test_modules(mlua_mod_pico_stdio_uart_test
    pico.stdio.uart.test.lua)
target_link_libraries(mlua_mod_pico_stdio_uart_test INTERFACE
    mlua_mod_hardware_gpio
    mlua_mod_hardware_uart
    mlua_mod_mlua_list
    mlua_mod_mlua_testing_uart
    mlua_mod_pico
    mlua_mod_pico_stdio_uart
)

mlua_add_c_module(mlua_mod_pico_stdio_usb pico.stdio.usb.c)
target_link_libraries(mlua_mod_pico_stdio_usb INTERFACE
    pico_stdio_usb
)

mlua_add_c_module(mlua_mod_pico_stdlib pico.stdlib.c)
target_link_libraries(mlua_mod_pico_stdlib INTERFACE
    pico_stdlib
)

mlua_add_lua_test_modules(mlua_mod_pico_stdlib_test pico.stdlib.test.lua)
target_link_libraries(mlua_mod_pico_stdlib_test INTERFACE
    mlua_mod_hardware_clocks
    mlua_mod_mlua_testing_clocks
    mlua_mod_pico_stdlib
)

mlua_add_c_module(mlua_mod_pico_time pico.time.c)
target_link_libraries(mlua_mod_pico_time INTERFACE
    hardware_timer
    mlua_mod_mlua_event_headers
    mlua_mod_mlua_int64
    pico_time
)

mlua_add_lua_test_modules(mlua_mod_pico_time_test pico.time.test.lua)
target_link_libraries(mlua_mod_pico_time_test INTERFACE
    mlua_mod_mlua_int64
    mlua_mod_mlua_list
    mlua_mod_mlua_thread
    mlua_mod_pico_time
    mlua_mod_table
)

mlua_add_c_module(mlua_mod_pico_unique_id pico.unique_id.c)
target_link_libraries(mlua_mod_pico_unique_id INTERFACE
    pico_unique_id
)

mlua_add_lua_test_modules(mlua_mod_pico_unique_id_test pico.unique_id.test.lua)
target_link_libraries(mlua_mod_pico_unique_id_test INTERFACE
    mlua_mod_pico_unique_id
    mlua_mod_string
)

set(MLUA_TEST_TARGET_FILTER "${MLUA_TEST_TARGET_FILTER}" CACHE STRING
    "Test target filter regexp"
)
get_property(TESTS GLOBAL PROPERTY mlua_test_targets)
if(NOT "${MLUA_TEST_TARGET_FILTER}" STREQUAL "")
    list(FILTER TESTS INCLUDE REGEX "${MLUA_TEST_TARGET_FILTER}")
endif()

add_executable(mlua_tests)
mlua_add_config_module(mlua_tests)
target_compile_definitions(mlua_tests PRIVATE
    MLUA_MAIN_MODULE=mlua.testing
    MLUA_SYMBOL_HASH_DEBUG=0
    PICO_MAX_SHARED_IRQ_HANDLERS=16
)
mlua_target_config(mlua_tests
    HASH_SYMBOL_TABLES:integer=MLUA_HASH_SYMBOL_TABLES
    I2C_MASTER_SCL:integer=5
    I2C_MASTER_SDA:integer=4
    I2C_SLAVE_SCL:integer=7
    I2C_SLAVE_SDA:integer=6
    a:integer=1
    b:string=\"test\"
)
target_link_libraries(mlua_tests PRIVATE
    mlua_mod_mlua_stdio
    mlua_mod_mlua_testing
    mlua_mod_mlua_thread
    pico_stdlib
    ${TESTS}
)
pico_add_extra_outputs(mlua_tests)
